// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_decimal128_from_double") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "drop table if exists test_cast_to_decimal_38_0_from_double_0_nullable;"
    sql "create table test_cast_to_decimal_38_0_from_double_0_nullable(f1 int, f2 double) properties('replication_num'='1');"
    sql """insert into test_cast_to_decimal_38_0_from_double_0_nullable values (0, "0.03"),(1, "1.03"),(2, "9.03"),(3, "9999999999999999999999999999999999999.03"),(4, "90000000000000000000000000000000000000.03"),(5, "90000000000000000000000000000000000001.03"),(6, "0.09"),(7, "1.09"),(8, "9.09"),(9, "9999999999999999999999999999999999999.09"),(10, "90000000000000000000000000000000000000.09"),(11, "90000000000000000000000000000000000001.09"),(12, "-0.03"),(13, "-1.03"),(14, "-9.03"),(15, "-9999999999999999999999999999999999999.03"),(16, "-90000000000000000000000000000000000000.03"),(17, "-90000000000000000000000000000000000001.03"),(18, "-0.09"),(19, "-1.09"),
      (20, "-9.09"),(21, "-9999999999999999999999999999999999999.09"),(22, "-90000000000000000000000000000000000000.09"),(23, "-90000000000000000000000000000000000001.09")
      ,(24, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as decimalv3(38, 0)) from test_cast_to_decimal_38_0_from_double_0_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as decimalv3(38, 0)) from test_cast_to_decimal_38_0_from_double_0_nullable order by 1;'

    sql "drop table if exists test_cast_to_decimal_38_0_from_double_0_not_nullable;"
    sql "create table test_cast_to_decimal_38_0_from_double_0_not_nullable(f1 int, f2 double) properties('replication_num'='1');"
    sql """insert into test_cast_to_decimal_38_0_from_double_0_not_nullable values (0, "0.03"),(1, "1.03"),(2, "9.03"),(3, "9999999999999999999999999999999999999.03"),(4, "90000000000000000000000000000000000000.03"),(5, "90000000000000000000000000000000000001.03"),(6, "0.09"),(7, "1.09"),(8, "9.09"),(9, "9999999999999999999999999999999999999.09"),(10, "90000000000000000000000000000000000000.09"),(11, "90000000000000000000000000000000000001.09"),(12, "-0.03"),(13, "-1.03"),(14, "-9.03"),(15, "-9999999999999999999999999999999999999.03"),(16, "-90000000000000000000000000000000000000.03"),(17, "-90000000000000000000000000000000000001.03"),(18, "-0.09"),(19, "-1.09"),
      (20, "-9.09"),(21, "-9999999999999999999999999999999999999.09"),(22, "-90000000000000000000000000000000000000.09"),(23, "-90000000000000000000000000000000000001.09");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as decimalv3(38, 0)) from test_cast_to_decimal_38_0_from_double_0_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as decimalv3(38, 0)) from test_cast_to_decimal_38_0_from_double_0_not_nullable order by 1;'

    sql "drop table if exists test_cast_to_decimal_38_19_from_double_1_nullable;"
    sql "create table test_cast_to_decimal_38_19_from_double_1_nullable(f1 int, f2 double) properties('replication_num'='1');"
    sql """insert into test_cast_to_decimal_38_19_from_double_1_nullable values (0, "0.00000000000000000003"),(1, "0.00000000000000000013"),(2, "0.00000000000000000093"),(3, "0.09999999999999999993"),(4, "0.90000000000000000003"),(5, "0.90000000000000000013"),(6, "0.99999999999999999983"),(7, "0.99999999999999999993"),(8, "1.00000000000000000003"),(9, "1.00000000000000000013"),(10, "1.00000000000000000093"),(11, "1.09999999999999999993"),(12, "1.90000000000000000003"),(13, "1.90000000000000000013"),(14, "1.99999999999999999983"),(15, "1.99999999999999999993"),(16, "9.00000000000000000003"),(17, "9.00000000000000000013"),(18, "9.00000000000000000093"),(19, "9.09999999999999999993"),
      (20, "9.90000000000000000003"),(21, "9.90000000000000000013"),(22, "9.99999999999999999983"),(23, "9.99999999999999999993"),(24, "999999999999999999.00000000000000000003"),(25, "999999999999999999.00000000000000000013"),(26, "999999999999999999.00000000000000000093"),(27, "999999999999999999.09999999999999999993"),(28, "999999999999999999.90000000000000000003"),(29, "999999999999999999.90000000000000000013"),(30, "999999999999999999.99999999999999999983"),(31, "999999999999999999.99999999999999999993"),(32, "9000000000000000000.00000000000000000003"),(33, "9000000000000000000.00000000000000000013"),(34, "9000000000000000000.00000000000000000093"),(35, "9000000000000000000.09999999999999999993"),(36, "9000000000000000000.90000000000000000003"),(37, "9000000000000000000.90000000000000000013"),(38, "9000000000000000000.99999999999999999983"),(39, "9000000000000000000.99999999999999999993"),
      (40, "9000000000000000001.00000000000000000003"),(41, "9000000000000000001.00000000000000000013"),(42, "9000000000000000001.00000000000000000093"),(43, "9000000000000000001.09999999999999999993"),(44, "9000000000000000001.90000000000000000003"),(45, "9000000000000000001.90000000000000000013"),(46, "9000000000000000001.99999999999999999983"),(47, "9000000000000000001.99999999999999999993"),(48, "0.00000000000000000009"),(49, "0.00000000000000000019"),(50, "0.00000000000000000099"),(51, "0.09999999999999999999"),(52, "0.90000000000000000009"),(53, "0.90000000000000000019"),(54, "0.99999999999999999989"),(55, "0.99999999999999999999"),(56, "1.00000000000000000009"),(57, "1.00000000000000000019"),(58, "1.00000000000000000099"),(59, "1.09999999999999999999"),
      (60, "1.90000000000000000009"),(61, "1.90000000000000000019"),(62, "1.99999999999999999989"),(63, "1.99999999999999999999"),(64, "9.00000000000000000009"),(65, "9.00000000000000000019"),(66, "9.00000000000000000099"),(67, "9.09999999999999999999"),(68, "9.90000000000000000009"),(69, "9.90000000000000000019"),(70, "9.99999999999999999989"),(71, "9.99999999999999999999"),(72, "999999999999999999.00000000000000000009"),(73, "999999999999999999.00000000000000000019"),(74, "999999999999999999.00000000000000000099"),(75, "999999999999999999.09999999999999999999"),(76, "999999999999999999.90000000000000000009"),(77, "999999999999999999.90000000000000000019"),(78, "999999999999999999.99999999999999999989"),(79, "999999999999999999.99999999999999999999"),
      (80, "9000000000000000000.00000000000000000009"),(81, "9000000000000000000.00000000000000000019"),(82, "9000000000000000000.00000000000000000099"),(83, "9000000000000000000.09999999999999999999"),(84, "9000000000000000000.90000000000000000009"),(85, "9000000000000000000.90000000000000000019"),(86, "9000000000000000000.99999999999999999989"),(87, "9000000000000000000.99999999999999999999"),(88, "9000000000000000001.00000000000000000009"),(89, "9000000000000000001.00000000000000000019"),(90, "9000000000000000001.00000000000000000099"),(91, "9000000000000000001.09999999999999999999"),(92, "9000000000000000001.90000000000000000009"),(93, "9000000000000000001.90000000000000000019"),(94, "9000000000000000001.99999999999999999989"),(95, "9000000000000000001.99999999999999999999"),(96, "-0.00000000000000000003"),(97, "-0.00000000000000000013"),(98, "-0.00000000000000000093"),(99, "-0.09999999999999999993"),
      (100, "-0.90000000000000000003"),(101, "-0.90000000000000000013"),(102, "-0.99999999999999999983"),(103, "-0.99999999999999999993"),(104, "-1.00000000000000000003"),(105, "-1.00000000000000000013"),(106, "-1.00000000000000000093"),(107, "-1.09999999999999999993"),(108, "-1.90000000000000000003"),(109, "-1.90000000000000000013"),(110, "-1.99999999999999999983"),(111, "-1.99999999999999999993"),(112, "-9.00000000000000000003"),(113, "-9.00000000000000000013"),(114, "-9.00000000000000000093"),(115, "-9.09999999999999999993"),(116, "-9.90000000000000000003"),(117, "-9.90000000000000000013"),(118, "-9.99999999999999999983"),(119, "-9.99999999999999999993"),
      (120, "-999999999999999999.00000000000000000003"),(121, "-999999999999999999.00000000000000000013"),(122, "-999999999999999999.00000000000000000093"),(123, "-999999999999999999.09999999999999999993"),(124, "-999999999999999999.90000000000000000003"),(125, "-999999999999999999.90000000000000000013"),(126, "-999999999999999999.99999999999999999983"),(127, "-999999999999999999.99999999999999999993"),(128, "-9000000000000000000.00000000000000000003"),(129, "-9000000000000000000.00000000000000000013"),(130, "-9000000000000000000.00000000000000000093"),(131, "-9000000000000000000.09999999999999999993"),(132, "-9000000000000000000.90000000000000000003"),(133, "-9000000000000000000.90000000000000000013"),(134, "-9000000000000000000.99999999999999999983"),(135, "-9000000000000000000.99999999999999999993"),(136, "-9000000000000000001.00000000000000000003"),(137, "-9000000000000000001.00000000000000000013"),(138, "-9000000000000000001.00000000000000000093"),(139, "-9000000000000000001.09999999999999999993"),
      (140, "-9000000000000000001.90000000000000000003"),(141, "-9000000000000000001.90000000000000000013"),(142, "-9000000000000000001.99999999999999999983"),(143, "-9000000000000000001.99999999999999999993"),(144, "-0.00000000000000000009"),(145, "-0.00000000000000000019"),(146, "-0.00000000000000000099"),(147, "-0.09999999999999999999"),(148, "-0.90000000000000000009"),(149, "-0.90000000000000000019"),(150, "-0.99999999999999999989"),(151, "-0.99999999999999999999"),(152, "-1.00000000000000000009"),(153, "-1.00000000000000000019"),(154, "-1.00000000000000000099"),(155, "-1.09999999999999999999"),(156, "-1.90000000000000000009"),(157, "-1.90000000000000000019"),(158, "-1.99999999999999999989"),(159, "-1.99999999999999999999"),
      (160, "-9.00000000000000000009"),(161, "-9.00000000000000000019"),(162, "-9.00000000000000000099"),(163, "-9.09999999999999999999"),(164, "-9.90000000000000000009"),(165, "-9.90000000000000000019"),(166, "-9.99999999999999999989"),(167, "-9.99999999999999999999"),(168, "-999999999999999999.00000000000000000009"),(169, "-999999999999999999.00000000000000000019"),(170, "-999999999999999999.00000000000000000099"),(171, "-999999999999999999.09999999999999999999"),(172, "-999999999999999999.90000000000000000009"),(173, "-999999999999999999.90000000000000000019"),(174, "-999999999999999999.99999999999999999989"),(175, "-999999999999999999.99999999999999999999"),(176, "-9000000000000000000.00000000000000000009"),(177, "-9000000000000000000.00000000000000000019"),(178, "-9000000000000000000.00000000000000000099"),(179, "-9000000000000000000.09999999999999999999"),
      (180, "-9000000000000000000.90000000000000000009"),(181, "-9000000000000000000.90000000000000000019"),(182, "-9000000000000000000.99999999999999999989"),(183, "-9000000000000000000.99999999999999999999"),(184, "-9000000000000000001.00000000000000000009"),(185, "-9000000000000000001.00000000000000000019"),(186, "-9000000000000000001.00000000000000000099"),(187, "-9000000000000000001.09999999999999999999"),(188, "-9000000000000000001.90000000000000000009"),(189, "-9000000000000000001.90000000000000000019"),(190, "-9000000000000000001.99999999999999999989"),(191, "-9000000000000000001.99999999999999999999")
      ,(192, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_1_strict 'select f1, cast(f2 as decimalv3(38, 19)) from test_cast_to_decimal_38_19_from_double_1_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_1_non_strict 'select f1, cast(f2 as decimalv3(38, 19)) from test_cast_to_decimal_38_19_from_double_1_nullable order by 1;'

    sql "drop table if exists test_cast_to_decimal_38_19_from_double_1_not_nullable;"
    sql "create table test_cast_to_decimal_38_19_from_double_1_not_nullable(f1 int, f2 double) properties('replication_num'='1');"
    sql """insert into test_cast_to_decimal_38_19_from_double_1_not_nullable values (0, "0.00000000000000000003"),(1, "0.00000000000000000013"),(2, "0.00000000000000000093"),(3, "0.09999999999999999993"),(4, "0.90000000000000000003"),(5, "0.90000000000000000013"),(6, "0.99999999999999999983"),(7, "0.99999999999999999993"),(8, "1.00000000000000000003"),(9, "1.00000000000000000013"),(10, "1.00000000000000000093"),(11, "1.09999999999999999993"),(12, "1.90000000000000000003"),(13, "1.90000000000000000013"),(14, "1.99999999999999999983"),(15, "1.99999999999999999993"),(16, "9.00000000000000000003"),(17, "9.00000000000000000013"),(18, "9.00000000000000000093"),(19, "9.09999999999999999993"),
      (20, "9.90000000000000000003"),(21, "9.90000000000000000013"),(22, "9.99999999999999999983"),(23, "9.99999999999999999993"),(24, "999999999999999999.00000000000000000003"),(25, "999999999999999999.00000000000000000013"),(26, "999999999999999999.00000000000000000093"),(27, "999999999999999999.09999999999999999993"),(28, "999999999999999999.90000000000000000003"),(29, "999999999999999999.90000000000000000013"),(30, "999999999999999999.99999999999999999983"),(31, "999999999999999999.99999999999999999993"),(32, "9000000000000000000.00000000000000000003"),(33, "9000000000000000000.00000000000000000013"),(34, "9000000000000000000.00000000000000000093"),(35, "9000000000000000000.09999999999999999993"),(36, "9000000000000000000.90000000000000000003"),(37, "9000000000000000000.90000000000000000013"),(38, "9000000000000000000.99999999999999999983"),(39, "9000000000000000000.99999999999999999993"),
      (40, "9000000000000000001.00000000000000000003"),(41, "9000000000000000001.00000000000000000013"),(42, "9000000000000000001.00000000000000000093"),(43, "9000000000000000001.09999999999999999993"),(44, "9000000000000000001.90000000000000000003"),(45, "9000000000000000001.90000000000000000013"),(46, "9000000000000000001.99999999999999999983"),(47, "9000000000000000001.99999999999999999993"),(48, "0.00000000000000000009"),(49, "0.00000000000000000019"),(50, "0.00000000000000000099"),(51, "0.09999999999999999999"),(52, "0.90000000000000000009"),(53, "0.90000000000000000019"),(54, "0.99999999999999999989"),(55, "0.99999999999999999999"),(56, "1.00000000000000000009"),(57, "1.00000000000000000019"),(58, "1.00000000000000000099"),(59, "1.09999999999999999999"),
      (60, "1.90000000000000000009"),(61, "1.90000000000000000019"),(62, "1.99999999999999999989"),(63, "1.99999999999999999999"),(64, "9.00000000000000000009"),(65, "9.00000000000000000019"),(66, "9.00000000000000000099"),(67, "9.09999999999999999999"),(68, "9.90000000000000000009"),(69, "9.90000000000000000019"),(70, "9.99999999999999999989"),(71, "9.99999999999999999999"),(72, "999999999999999999.00000000000000000009"),(73, "999999999999999999.00000000000000000019"),(74, "999999999999999999.00000000000000000099"),(75, "999999999999999999.09999999999999999999"),(76, "999999999999999999.90000000000000000009"),(77, "999999999999999999.90000000000000000019"),(78, "999999999999999999.99999999999999999989"),(79, "999999999999999999.99999999999999999999"),
      (80, "9000000000000000000.00000000000000000009"),(81, "9000000000000000000.00000000000000000019"),(82, "9000000000000000000.00000000000000000099"),(83, "9000000000000000000.09999999999999999999"),(84, "9000000000000000000.90000000000000000009"),(85, "9000000000000000000.90000000000000000019"),(86, "9000000000000000000.99999999999999999989"),(87, "9000000000000000000.99999999999999999999"),(88, "9000000000000000001.00000000000000000009"),(89, "9000000000000000001.00000000000000000019"),(90, "9000000000000000001.00000000000000000099"),(91, "9000000000000000001.09999999999999999999"),(92, "9000000000000000001.90000000000000000009"),(93, "9000000000000000001.90000000000000000019"),(94, "9000000000000000001.99999999999999999989"),(95, "9000000000000000001.99999999999999999999"),(96, "-0.00000000000000000003"),(97, "-0.00000000000000000013"),(98, "-0.00000000000000000093"),(99, "-0.09999999999999999993"),
      (100, "-0.90000000000000000003"),(101, "-0.90000000000000000013"),(102, "-0.99999999999999999983"),(103, "-0.99999999999999999993"),(104, "-1.00000000000000000003"),(105, "-1.00000000000000000013"),(106, "-1.00000000000000000093"),(107, "-1.09999999999999999993"),(108, "-1.90000000000000000003"),(109, "-1.90000000000000000013"),(110, "-1.99999999999999999983"),(111, "-1.99999999999999999993"),(112, "-9.00000000000000000003"),(113, "-9.00000000000000000013"),(114, "-9.00000000000000000093"),(115, "-9.09999999999999999993"),(116, "-9.90000000000000000003"),(117, "-9.90000000000000000013"),(118, "-9.99999999999999999983"),(119, "-9.99999999999999999993"),
      (120, "-999999999999999999.00000000000000000003"),(121, "-999999999999999999.00000000000000000013"),(122, "-999999999999999999.00000000000000000093"),(123, "-999999999999999999.09999999999999999993"),(124, "-999999999999999999.90000000000000000003"),(125, "-999999999999999999.90000000000000000013"),(126, "-999999999999999999.99999999999999999983"),(127, "-999999999999999999.99999999999999999993"),(128, "-9000000000000000000.00000000000000000003"),(129, "-9000000000000000000.00000000000000000013"),(130, "-9000000000000000000.00000000000000000093"),(131, "-9000000000000000000.09999999999999999993"),(132, "-9000000000000000000.90000000000000000003"),(133, "-9000000000000000000.90000000000000000013"),(134, "-9000000000000000000.99999999999999999983"),(135, "-9000000000000000000.99999999999999999993"),(136, "-9000000000000000001.00000000000000000003"),(137, "-9000000000000000001.00000000000000000013"),(138, "-9000000000000000001.00000000000000000093"),(139, "-9000000000000000001.09999999999999999993"),
      (140, "-9000000000000000001.90000000000000000003"),(141, "-9000000000000000001.90000000000000000013"),(142, "-9000000000000000001.99999999999999999983"),(143, "-9000000000000000001.99999999999999999993"),(144, "-0.00000000000000000009"),(145, "-0.00000000000000000019"),(146, "-0.00000000000000000099"),(147, "-0.09999999999999999999"),(148, "-0.90000000000000000009"),(149, "-0.90000000000000000019"),(150, "-0.99999999999999999989"),(151, "-0.99999999999999999999"),(152, "-1.00000000000000000009"),(153, "-1.00000000000000000019"),(154, "-1.00000000000000000099"),(155, "-1.09999999999999999999"),(156, "-1.90000000000000000009"),(157, "-1.90000000000000000019"),(158, "-1.99999999999999999989"),(159, "-1.99999999999999999999"),
      (160, "-9.00000000000000000009"),(161, "-9.00000000000000000019"),(162, "-9.00000000000000000099"),(163, "-9.09999999999999999999"),(164, "-9.90000000000000000009"),(165, "-9.90000000000000000019"),(166, "-9.99999999999999999989"),(167, "-9.99999999999999999999"),(168, "-999999999999999999.00000000000000000009"),(169, "-999999999999999999.00000000000000000019"),(170, "-999999999999999999.00000000000000000099"),(171, "-999999999999999999.09999999999999999999"),(172, "-999999999999999999.90000000000000000009"),(173, "-999999999999999999.90000000000000000019"),(174, "-999999999999999999.99999999999999999989"),(175, "-999999999999999999.99999999999999999999"),(176, "-9000000000000000000.00000000000000000009"),(177, "-9000000000000000000.00000000000000000019"),(178, "-9000000000000000000.00000000000000000099"),(179, "-9000000000000000000.09999999999999999999"),
      (180, "-9000000000000000000.90000000000000000009"),(181, "-9000000000000000000.90000000000000000019"),(182, "-9000000000000000000.99999999999999999989"),(183, "-9000000000000000000.99999999999999999999"),(184, "-9000000000000000001.00000000000000000009"),(185, "-9000000000000000001.00000000000000000019"),(186, "-9000000000000000001.00000000000000000099"),(187, "-9000000000000000001.09999999999999999999"),(188, "-9000000000000000001.90000000000000000009"),(189, "-9000000000000000001.90000000000000000019"),(190, "-9000000000000000001.99999999999999999989"),(191, "-9000000000000000001.99999999999999999999");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_1_strict 'select f1, cast(f2 as decimalv3(38, 19)) from test_cast_to_decimal_38_19_from_double_1_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_1_non_strict 'select f1, cast(f2 as decimalv3(38, 19)) from test_cast_to_decimal_38_19_from_double_1_not_nullable order by 1;'

    sql "drop table if exists test_cast_to_decimal_38_37_from_double_2_nullable;"
    sql "create table test_cast_to_decimal_38_37_from_double_2_nullable(f1 int, f2 double) properties('replication_num'='1');"
    sql """insert into test_cast_to_decimal_38_37_from_double_2_nullable values (0, "0.00000000000000000000000000000000000003"),(1, "0.00000000000000000000000000000000000013"),(2, "0.00000000000000000000000000000000000093"),(3, "0.09999999999999999999999999999999999993"),(4, "0.90000000000000000000000000000000000003"),(5, "0.90000000000000000000000000000000000013"),(6, "0.99999999999999999999999999999999999983"),(7, "0.99999999999999999999999999999999999993"),(8, "1.00000000000000000000000000000000000003"),(9, "1.00000000000000000000000000000000000013"),(10, "1.00000000000000000000000000000000000093"),(11, "1.09999999999999999999999999999999999993"),(12, "1.90000000000000000000000000000000000003"),(13, "1.90000000000000000000000000000000000013"),(14, "1.99999999999999999999999999999999999983"),(15, "1.99999999999999999999999999999999999993"),(16, "8.00000000000000000000000000000000000003"),(17, "8.00000000000000000000000000000000000013"),(18, "8.00000000000000000000000000000000000093"),(19, "8.09999999999999999999999999999999999993"),
      (20, "8.90000000000000000000000000000000000003"),(21, "8.90000000000000000000000000000000000013"),(22, "8.99999999999999999999999999999999999983"),(23, "8.99999999999999999999999999999999999993"),(24, "9.00000000000000000000000000000000000003"),(25, "9.00000000000000000000000000000000000013"),(26, "9.00000000000000000000000000000000000093"),(27, "9.09999999999999999999999999999999999993"),(28, "9.90000000000000000000000000000000000003"),(29, "9.90000000000000000000000000000000000013"),(30, "0.00000000000000000000000000000000000009"),(31, "0.00000000000000000000000000000000000019"),(32, "0.00000000000000000000000000000000000099"),(33, "0.09999999999999999999999999999999999999"),(34, "0.90000000000000000000000000000000000009"),(35, "0.90000000000000000000000000000000000019"),(36, "0.99999999999999999999999999999999999989"),(37, "0.99999999999999999999999999999999999999"),(38, "1.00000000000000000000000000000000000009"),(39, "1.00000000000000000000000000000000000019"),
      (40, "1.00000000000000000000000000000000000099"),(41, "1.09999999999999999999999999999999999999"),(42, "1.90000000000000000000000000000000000009"),(43, "1.90000000000000000000000000000000000019"),(44, "1.99999999999999999999999999999999999989"),(45, "1.99999999999999999999999999999999999999"),(46, "8.00000000000000000000000000000000000009"),(47, "8.00000000000000000000000000000000000019"),(48, "8.00000000000000000000000000000000000099"),(49, "8.09999999999999999999999999999999999999"),(50, "8.90000000000000000000000000000000000009"),(51, "8.90000000000000000000000000000000000019"),(52, "8.99999999999999999999999999999999999989"),(53, "8.99999999999999999999999999999999999999"),(54, "9.00000000000000000000000000000000000003"),(55, "9.00000000000000000000000000000000000013"),(56, "9.00000000000000000000000000000000000093"),(57, "9.09999999999999999999999999999999999993"),(58, "9.90000000000000000000000000000000000003"),(59, "9.90000000000000000000000000000000000013"),
      (60, "-0.00000000000000000000000000000000000003"),(61, "-0.00000000000000000000000000000000000013"),(62, "-0.00000000000000000000000000000000000093"),(63, "-0.09999999999999999999999999999999999993"),(64, "-0.90000000000000000000000000000000000003"),(65, "-0.90000000000000000000000000000000000013"),(66, "-0.99999999999999999999999999999999999983"),(67, "-0.99999999999999999999999999999999999993"),(68, "-1.00000000000000000000000000000000000003"),(69, "-1.00000000000000000000000000000000000013"),(70, "-1.00000000000000000000000000000000000093"),(71, "-1.09999999999999999999999999999999999993"),(72, "-1.90000000000000000000000000000000000003"),(73, "-1.90000000000000000000000000000000000013"),(74, "-1.99999999999999999999999999999999999983"),(75, "-1.99999999999999999999999999999999999993"),(76, "-8.00000000000000000000000000000000000003"),(77, "-8.00000000000000000000000000000000000013"),(78, "-8.00000000000000000000000000000000000093"),(79, "-8.09999999999999999999999999999999999993"),
      (80, "-8.90000000000000000000000000000000000003"),(81, "-8.90000000000000000000000000000000000013"),(82, "-8.99999999999999999999999999999999999983"),(83, "-8.99999999999999999999999999999999999993"),(84, "-9.00000000000000000000000000000000000003"),(85, "-9.00000000000000000000000000000000000013"),(86, "-9.00000000000000000000000000000000000093"),(87, "-9.09999999999999999999999999999999999993"),(88, "-9.90000000000000000000000000000000000003"),(89, "-9.90000000000000000000000000000000000013"),(90, "-0.00000000000000000000000000000000000009"),(91, "-0.00000000000000000000000000000000000019"),(92, "-0.00000000000000000000000000000000000099"),(93, "-0.09999999999999999999999999999999999999"),(94, "-0.90000000000000000000000000000000000009"),(95, "-0.90000000000000000000000000000000000019"),(96, "-0.99999999999999999999999999999999999989"),(97, "-0.99999999999999999999999999999999999999"),(98, "-1.00000000000000000000000000000000000009"),(99, "-1.00000000000000000000000000000000000019"),
      (100, "-1.00000000000000000000000000000000000099"),(101, "-1.09999999999999999999999999999999999999"),(102, "-1.90000000000000000000000000000000000009"),(103, "-1.90000000000000000000000000000000000019"),(104, "-1.99999999999999999999999999999999999989"),(105, "-1.99999999999999999999999999999999999999"),(106, "-8.00000000000000000000000000000000000009"),(107, "-8.00000000000000000000000000000000000019"),(108, "-8.00000000000000000000000000000000000099"),(109, "-8.09999999999999999999999999999999999999"),(110, "-8.90000000000000000000000000000000000009"),(111, "-8.90000000000000000000000000000000000019"),(112, "-8.99999999999999999999999999999999999989"),(113, "-8.99999999999999999999999999999999999999"),(114, "-9.00000000000000000000000000000000000003"),(115, "-9.00000000000000000000000000000000000013"),(116, "-9.00000000000000000000000000000000000093"),(117, "-9.09999999999999999999999999999999999993"),(118, "-9.90000000000000000000000000000000000003"),(119, "-9.90000000000000000000000000000000000013")
      ,(120, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_2_strict 'select f1, cast(f2 as decimalv3(38, 37)) from test_cast_to_decimal_38_37_from_double_2_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_2_non_strict 'select f1, cast(f2 as decimalv3(38, 37)) from test_cast_to_decimal_38_37_from_double_2_nullable order by 1;'

    sql "drop table if exists test_cast_to_decimal_38_37_from_double_2_not_nullable;"
    sql "create table test_cast_to_decimal_38_37_from_double_2_not_nullable(f1 int, f2 double) properties('replication_num'='1');"
    sql """insert into test_cast_to_decimal_38_37_from_double_2_not_nullable values (0, "0.00000000000000000000000000000000000003"),(1, "0.00000000000000000000000000000000000013"),(2, "0.00000000000000000000000000000000000093"),(3, "0.09999999999999999999999999999999999993"),(4, "0.90000000000000000000000000000000000003"),(5, "0.90000000000000000000000000000000000013"),(6, "0.99999999999999999999999999999999999983"),(7, "0.99999999999999999999999999999999999993"),(8, "1.00000000000000000000000000000000000003"),(9, "1.00000000000000000000000000000000000013"),(10, "1.00000000000000000000000000000000000093"),(11, "1.09999999999999999999999999999999999993"),(12, "1.90000000000000000000000000000000000003"),(13, "1.90000000000000000000000000000000000013"),(14, "1.99999999999999999999999999999999999983"),(15, "1.99999999999999999999999999999999999993"),(16, "8.00000000000000000000000000000000000003"),(17, "8.00000000000000000000000000000000000013"),(18, "8.00000000000000000000000000000000000093"),(19, "8.09999999999999999999999999999999999993"),
      (20, "8.90000000000000000000000000000000000003"),(21, "8.90000000000000000000000000000000000013"),(22, "8.99999999999999999999999999999999999983"),(23, "8.99999999999999999999999999999999999993"),(24, "9.00000000000000000000000000000000000003"),(25, "9.00000000000000000000000000000000000013"),(26, "9.00000000000000000000000000000000000093"),(27, "9.09999999999999999999999999999999999993"),(28, "9.90000000000000000000000000000000000003"),(29, "9.90000000000000000000000000000000000013"),(30, "0.00000000000000000000000000000000000009"),(31, "0.00000000000000000000000000000000000019"),(32, "0.00000000000000000000000000000000000099"),(33, "0.09999999999999999999999999999999999999"),(34, "0.90000000000000000000000000000000000009"),(35, "0.90000000000000000000000000000000000019"),(36, "0.99999999999999999999999999999999999989"),(37, "0.99999999999999999999999999999999999999"),(38, "1.00000000000000000000000000000000000009"),(39, "1.00000000000000000000000000000000000019"),
      (40, "1.00000000000000000000000000000000000099"),(41, "1.09999999999999999999999999999999999999"),(42, "1.90000000000000000000000000000000000009"),(43, "1.90000000000000000000000000000000000019"),(44, "1.99999999999999999999999999999999999989"),(45, "1.99999999999999999999999999999999999999"),(46, "8.00000000000000000000000000000000000009"),(47, "8.00000000000000000000000000000000000019"),(48, "8.00000000000000000000000000000000000099"),(49, "8.09999999999999999999999999999999999999"),(50, "8.90000000000000000000000000000000000009"),(51, "8.90000000000000000000000000000000000019"),(52, "8.99999999999999999999999999999999999989"),(53, "8.99999999999999999999999999999999999999"),(54, "9.00000000000000000000000000000000000003"),(55, "9.00000000000000000000000000000000000013"),(56, "9.00000000000000000000000000000000000093"),(57, "9.09999999999999999999999999999999999993"),(58, "9.90000000000000000000000000000000000003"),(59, "9.90000000000000000000000000000000000013"),
      (60, "-0.00000000000000000000000000000000000003"),(61, "-0.00000000000000000000000000000000000013"),(62, "-0.00000000000000000000000000000000000093"),(63, "-0.09999999999999999999999999999999999993"),(64, "-0.90000000000000000000000000000000000003"),(65, "-0.90000000000000000000000000000000000013"),(66, "-0.99999999999999999999999999999999999983"),(67, "-0.99999999999999999999999999999999999993"),(68, "-1.00000000000000000000000000000000000003"),(69, "-1.00000000000000000000000000000000000013"),(70, "-1.00000000000000000000000000000000000093"),(71, "-1.09999999999999999999999999999999999993"),(72, "-1.90000000000000000000000000000000000003"),(73, "-1.90000000000000000000000000000000000013"),(74, "-1.99999999999999999999999999999999999983"),(75, "-1.99999999999999999999999999999999999993"),(76, "-8.00000000000000000000000000000000000003"),(77, "-8.00000000000000000000000000000000000013"),(78, "-8.00000000000000000000000000000000000093"),(79, "-8.09999999999999999999999999999999999993"),
      (80, "-8.90000000000000000000000000000000000003"),(81, "-8.90000000000000000000000000000000000013"),(82, "-8.99999999999999999999999999999999999983"),(83, "-8.99999999999999999999999999999999999993"),(84, "-9.00000000000000000000000000000000000003"),(85, "-9.00000000000000000000000000000000000013"),(86, "-9.00000000000000000000000000000000000093"),(87, "-9.09999999999999999999999999999999999993"),(88, "-9.90000000000000000000000000000000000003"),(89, "-9.90000000000000000000000000000000000013"),(90, "-0.00000000000000000000000000000000000009"),(91, "-0.00000000000000000000000000000000000019"),(92, "-0.00000000000000000000000000000000000099"),(93, "-0.09999999999999999999999999999999999999"),(94, "-0.90000000000000000000000000000000000009"),(95, "-0.90000000000000000000000000000000000019"),(96, "-0.99999999999999999999999999999999999989"),(97, "-0.99999999999999999999999999999999999999"),(98, "-1.00000000000000000000000000000000000009"),(99, "-1.00000000000000000000000000000000000019"),
      (100, "-1.00000000000000000000000000000000000099"),(101, "-1.09999999999999999999999999999999999999"),(102, "-1.90000000000000000000000000000000000009"),(103, "-1.90000000000000000000000000000000000019"),(104, "-1.99999999999999999999999999999999999989"),(105, "-1.99999999999999999999999999999999999999"),(106, "-8.00000000000000000000000000000000000009"),(107, "-8.00000000000000000000000000000000000019"),(108, "-8.00000000000000000000000000000000000099"),(109, "-8.09999999999999999999999999999999999999"),(110, "-8.90000000000000000000000000000000000009"),(111, "-8.90000000000000000000000000000000000019"),(112, "-8.99999999999999999999999999999999999989"),(113, "-8.99999999999999999999999999999999999999"),(114, "-9.00000000000000000000000000000000000003"),(115, "-9.00000000000000000000000000000000000013"),(116, "-9.00000000000000000000000000000000000093"),(117, "-9.09999999999999999999999999999999999993"),(118, "-9.90000000000000000000000000000000000003"),(119, "-9.90000000000000000000000000000000000013");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_2_strict 'select f1, cast(f2 as decimalv3(38, 37)) from test_cast_to_decimal_38_37_from_double_2_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_2_non_strict 'select f1, cast(f2 as decimalv3(38, 37)) from test_cast_to_decimal_38_37_from_double_2_not_nullable order by 1;'

}